package com.hxd.otc.module.order.presenter;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseBean;
import com.hxd.otc.dialog.OrderPaymentMethodPopupWindow;
import com.hxd.otc.module.my.bean.BankCardBean;
import com.hxd.otc.module.my.model.BankModel;
import com.hxd.otc.module.order.contract.OrderConfirmPaymentContract;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;
import com.hxd.otc.utils.ResourceUtil;

import java.util.ArrayList;

/**
 * Created by lzy on 2019/1/18 0018.
 * description ${订单确认支付Presenter}
 */
public class OrderConfirmPaymentPresenter extends BasePresenter<OrderConfirmPaymentContract.IView> implements OrderConfirmPaymentContract.IPresenter {
    private final BankModel mBankModel;
    private ArrayList<BankCardBean> mBankCardBeans;
    private BankCardBean mSelBankCardBean;

    public OrderConfirmPaymentPresenter(OrderConfirmPaymentContract.IView iView) {
        super(iView);
        mBankModel = BankModel.getInstance();
    }

    @Override
    public void requestBankCardList(final boolean isInitiative) {
        mBankModel.getBankCardList(new BaseObserver<ArrayList<BankCardBean>>() {
            @Override
            public void onNext(String msg, ArrayList<BankCardBean> bankCardBeans) {
                mBankCardBeans = bankCardBeans;
                //补充手动输入选项
                BankCardBean bankCardBean = new BankCardBean();
                bankCardBean.setType(OrderPaymentMethodPopupWindow.BANK_TYPE_WRITE);
                bankCardBean.setBankName(ResourceUtil.getString(R.string.add_new_pay_method));
                mBankCardBeans.add(bankCardBean);
                mView.requestBankCardListSuccess(isInitiative);
            }

            @Override
            public void onError(int errType, String errMessage) {
                if (isInitiative) {
                    mView.showToast(errMessage);
                }
            }
        }, mView.<BaseBean<ArrayList<BankCardBean>>>bindAutoDispose());
    }

    @Override
    public ArrayList<BankCardBean> getBankCardList() {
        if (mBankCardBeans == null) {
            mView.showToast(ResourceUtil.getString(R.string.we_are_trying_to_retrieve_the_pay_method_information_for_you));
            requestBankCardList(true);
        }
        return mBankCardBeans;
    }

    @Override
    public void setSelBankCard(BankCardBean bankCardBean) {
        mSelBankCardBean = bankCardBean;
    }

    @Override
    public BankCardBean getSelBankCardBean() {
        return mSelBankCardBean;
    }
}
